package com.atguigu.yygh.cmn.controller;

import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.model.cmn.Dict;
import com.atguigu.yygh.param.cmn.cmnByIdParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

import com.atguigu.yygh.cmn.service.IDictService;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 组织架构表 前端控制器
 * </p>
 *
 * @author 方哥哥
 * @since 2022-03-19
 */
@RestController
@RequestMapping("/admin/cmn/dict/")
@Api(value = "DictController",tags = "字典设置管理")
public class DictController {

    @Resource
    private IDictService dictService;

    /**
     * 根据数据id查询子数据列表
     * @param param
     * @return
     */
    @ApiOperation(value = "根据数据id查询子数据列表")
    @PostMapping("findChildData/")
    public Result findChildData(@RequestBody cmnByIdParam param) {
        List<Dict> list = dictService.findChlidData(param);
        return new Result("200",list);
    }

    /**
     * 数据字典导出接口
     * @param response
     */
    @ApiOperation(value="导出")
    @GetMapping(value = "/exportData")
    public void exportData(HttpServletResponse response) {
        dictService.exportData(response);
    }

    /**
     * 数据字典导入接口
     * @param file
     * @return
     */
    @ApiOperation(value = "导入")
    @PostMapping("importData")
    public Result importData(MultipartFile file) {
        dictService.importData(file);
        return new Result();
    }

    @ApiOperation(value = "获取数据字典名称--通过Code与value")
    @PostMapping(value = "/getName")
    public String getName(@RequestParam("value") String value,@RequestParam(value = "dictcode",defaultValue = "") String dictcode) {
        return dictService.getDictName(value,dictcode);
    }

    @ApiOperation(value = "根据dictCode获取下级节点")
    @GetMapping(value = "/findByDictCode")
    public Result<List<Dict>> findByDictCode(@RequestParam(value = "dictCode") String dictCode) {
        List<Dict> list = dictService.findByDictCode(dictCode);
        return new Result<>(list);
    }

}

